package cn.org.eshow.webapp.action;

import cn.org.eshow.bean.query.OrderItemQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.model.OrderItem;
import cn.org.eshow.service.OrderItemManager;
import cn.org.eshow.util.PageUtil;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Results({@Result(name = "input", location = "add"),
        @Result(name = "list", type = "redirect", location = ""),
        @Result(name = "success", type = "redirect", location = "view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"list", "search", "view"})
public class OrderItemAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private OrderItemManager orderItemManager;

    private List<OrderItem> orderItems=new ArrayList<OrderItem>();
    private OrderItem orderItem=new OrderItem();
    private OrderItemQuery query = new OrderItemQuery();

    /**
     * @return
     */
    public String list() {
        orderItems = orderItemManager.list(query);
        return LIST;
    }

    /**
     * @return
     */
    public String search() {
        Page<OrderItem> page = orderItemManager.search(query);
        orderItems = page.getDataList();
        saveRequest("page", PageUtil.conversion(page));
        saveRequest("query", query);
        return LIST;
    }


    /**
     * @return
     */
    public String view() {
        if (id != null) {
            orderItem = orderItemManager.get(id);
        }
        return NONE;
    }


    public List<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }

    public OrderItem getOrderItem() {
        return orderItem;
    }

    public void setOrderItem(OrderItem orderItem) {
        this.orderItem = orderItem;
    }

    public OrderItemQuery getQuery() {
        return query;
    }

    public void setQuery(OrderItemQuery query) {
        this.query = query;
    }


}